using System;
using System.IO;
using System.Windows.Forms;

namespace OpenEdge.Utility
{
	/// <summary>
	/// Summary description for LogWriter.
	/// </summary>
	public class LogWriter : Writer
	{

		public LogWriter() 
		{
			
		}

		public LogWriter(string logPath) 
		{
			this.Open(logPath);
		}

		public void Open(string filePath) 
		{
            if (filePath.Length > 0)
            {
                this.fs = new FileStream(filePath,
                                        System.IO.FileMode.Append,
                                        System.IO.FileAccess.Write,
                                        System.IO.FileShare.Read);

                this.sw = new StreamWriter(this.fs);

                this.sw.AutoFlush = true;
            }
		}

		public void Close()
		{
            if (this.sw != null)
			    this.sw.Close();
            if (this.fs != null)
			    this.fs.Close();
		}

		public new void WriteHandler(string messageString)
		{
            messageString = "{" + DateTime.Now.ToString() + "} - " + messageString;
            if (this.sw != null)
            {
                this.sw.Write(messageString);
            }
		}

		public new void WriteLineHandler(string messageString)
		{
            messageString = "{" + DateTime.Now.ToString() + "} - " + messageString;
            if (this.sw != null)
            {
                this.sw.WriteLine(messageString);
            }
		}


	}
}
